import 'dart:typed_data';
import 'enums/index.dart';
import 'nexgo_platform_interface.dart';

class Nexgo {
  static Future<bool> init() {
    return NexgoPlatform.instance.init();
  }

  static Future<bool> printText({
    required String text,
    NexgoAlignEnum align = NexgoAlignEnum.left,
  }) {
    return NexgoPlatform.instance.printText(text: text, align: align);
  }

  static Future<bool> feed({
    required int val,
  }) {
    return NexgoPlatform.instance.feed(val: val);
  }

  static Future<bool> printImage({
    required Uint8List image,
    NexgoAlignEnum align = NexgoAlignEnum.center,
  }) {
    return NexgoPlatform.instance.printImage(image: image, align: align);
  }

  static Future<bool> setLED({
    required NexgoLightModeEnum light,
    bool enbeld = true,
  }) {
    return NexgoPlatform.instance.setLED(light: light, enbeld: enbeld);
  }

  static bool _ledLoading = false;
  static Future<void> setLEDLoading() async {
    setLEDClose();
    _ledLoading = true;
    while (_ledLoading) {
      await Nexgo.setLED(light: NexgoLightModeEnum.blue, enbeld: true);
      await Future.delayed(const Duration(milliseconds: 200));
      await Nexgo.setLED(light: NexgoLightModeEnum.yeelow, enbeld: true);
      await Future.delayed(const Duration(milliseconds: 200));
      await Nexgo.setLED(light: NexgoLightModeEnum.green, enbeld: true);
      await Future.delayed(const Duration(milliseconds: 200));
      await Nexgo.setLED(light: NexgoLightModeEnum.blue, enbeld: false);
      await Future.delayed(const Duration(milliseconds: 200));
      await Nexgo.setLED(light: NexgoLightModeEnum.yeelow, enbeld: false);
      await Future.delayed(const Duration(milliseconds: 200));
      await Nexgo.setLED(light: NexgoLightModeEnum.green, enbeld: false);
      await Future.delayed(const Duration(milliseconds: 200));
    }
  }

  static Future<void> setLEDClose() async {
    if (_ledLoading) _ledLoading = false;
    await Nexgo.setLED(light: NexgoLightModeEnum.blue, enbeld: false);
    await Nexgo.setLED(light: NexgoLightModeEnum.yeelow, enbeld: false);
    await Nexgo.setLED(light: NexgoLightModeEnum.green, enbeld: false);
    await Nexgo.setLED(light: NexgoLightModeEnum.red, enbeld: false);
  }
}
